package games.cowsAndBulls;

import java.util.Scanner;

/** Testing the game via console */

public class CowsAndBullsConsole {
	private static Scanner sc = new Scanner(System.in);

	public static void play() {
		System.out.print("Choose the number of digits [3 - 5]: ");
		int numberOfSymbols = readNumber();

		CowsAndBullsBusinessLogic game = new CowsAndBullsBusinessLogic(
				numberOfSymbols);

		System.out.println("The system has generated a random number. "
				+ "The first digit cannot be 0. Try to find it out.");

		while (!game.isWin()) {
			System.out.print("> ");
			int number = readNumber();
			game.getNumberFromClient(number);
			System.out.println(number + " - " + game.getNumberOfCows()
					+ " cows, " + game.getNumberOfBulls() + " bulls.");
		}
	}

	private static int readNumber() {
		String input = sc.nextLine();
		int num = 0;
		try {
			num = Integer.parseInt(input);
		} catch (NumberFormatException e) {
			System.out.println(input + " is not valid input.Try again!");
			readNumber();
		}

		return num;
	}
}
